{extend name="base" /}
{block name="body"}
<div class="layui-body">
    <!--tab标签-->
    <div class="layui-tab layui-tab-brief">
        <ul class="layui-tab-title">
            <li class="layui-this">文章管理</li>
            <li class=""><a href="{:url('admin/article/add')}">添加文章</a></li>
        </ul>
        <div class="layui-tab-content">

                <div class="layui-form-item">
                        <label class="layui-form-label">图片</label>
                        <div class="layui-input-block">
                            <img id="pre_img" style="height: 30px;" />
                            <button class="layui-btn layui-btn-sm" onclick="return false;" id="upload_img">
                                <i class="layui-icon">&#xe67c;</i>上传图片
                            </button>
                            <input type="hidden" name="img" value="">
                        </div>
                    </div>
            
        </div>
    </div>
</div>
{/block}

{block name="js"}
<script >
layui.use(['upload','jquery'],function () {
    $ = layui.jquery;
    var upload = layui.upload;
    //执行实例
    var uploadInst = upload.render({
        elem: '#upload_img' //绑定元素
        ,url: '/admin/article/upload' //上传接口
        ,accept:'images'
        ,done: function(res){
            //上传完毕回调
            $('#pre_img').attr('src',res.msg);
            $('input[name="img"]').val(res.msg);
        }
        ,error: function(){
            //请求异常回调
        }
    });
});
</script>

<script>
        layui.use('upload', function () {
            var upload = layui.upload,
                jq = layui.jquery;
            upload.render({
                url: '{:url("/admin/article/upload")}'
                , elem: '#image'
                , ext: 'jpg|png|gif'
                , area: ['500', '500px']
                , before: function (input) {
                    loading = layer.load(2, {
                        shade: [0.2, '#000']
                    });
                }
                , done: function (res) {
                    layer.close(loading);
                    jq('input[name=img]').val(res.path);
                    img.src = "" + res.path;
                    layer.msg(res.msg, { icon: 1, time: 1000 });
                }
            });
        })
        </script>

{/block}